//
//  WorkerResumeViewController.m
//  Btpin
//
//  Created by Vic on 2019/3/27.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "WorkerResumeViewController.h"
#import "PMineResumeInfoModel.h"
#import "ResumeWorkCell.h"

@interface WorkerResumeViewController ()
{
    PMineResumeInfoModel *infoModel;
    
    UIScrollView *bottomScrollView;
}
@end

@implementation WorkerResumeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadData];
//    [self initUI];
}
- (void)loadData {
    SVPHUDShow;
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
    dic = [UIToolsControl getPublicParameter];
    
    [BaseNetManager requestWithMethod:POST path:PersonMineResume_URL params:dic successBlock:^(NSDictionary * _Nonnull responseObject) {
        if ([responseObject[@"code"] integerValue] == 2000) {
            id data = responseObject[@"data"];
            self->infoModel = [[PMineResumeInfoModel alloc] init];
            [self->infoModel setValuesForKeysWithDictionary:data];
        }
        [self initUI];
        SVPHUDDismiss;
    } failurBlock:^(NSError * _Nonnull error) {
        SVPHUDError(NetErrorAlertText);
    }];
}
- (void)collectTap {
    NSLog(@"收藏");
}
- (void)initUI {
//    UIBarButtonItem *collect = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"collect_icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(collectTap)];
//    self.navigationItem.rightBarButtonItem = collect;
    
    bottomScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-SIMEmojKeyBoardkBottomNOSafeArea_Height-HeightOfStatusBarAndNavigationBar)];
    [self.view addSubview:bottomScrollView];
    
    UIView *topBgView = [UIToolsControl initViewWithFrame:CGRectMake(30*Scale, 0, WIDTH-60, 95*Scale) backgroundColor:COLOR_OF_WHITE];
    [bottomScrollView addSubview:topBgView];
    [topBgView borderColor:THEMECOLOR_OF_TEXT_cccccc borderWidth:lineH borderType:BorderSideTypeBottom];
    CGFloat nameWidth = [UIToolsControl textWidth:infoModel.name size:CGSizeMake(MAXFLOAT, 35*Scale) font:Font_27]+10*Scale;
    UILabel *nameLbl = [UIToolsControl initLabelWithFrame:CGRectMake(0, 20*Scale, nameWidth, 35*Scale) text:infoModel.name textColor:THEMECOLOR_OF_TEXT_333333 font:Font_27];
    nameLbl.font = FontBold(Font_27);
    [topBgView addSubview:nameLbl];
    
    UILabel *baseInfoLbl = [UIToolsControl initLabelWithFrame:CGRectMake(StartX(nameLbl), EndY(nameLbl), 260*Scale, 25*Scale) text:[NSString stringWithFormat:@"%@ %@ %@ %@", infoModel.residence, infoModel.age, infoModel.education_cn, infoModel.experience_cn] textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    [topBgView addSubview:baseInfoLbl];
    
    UIImageView *headerImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(ViewWidth(topBgView)-66*Scale, 20*Scale, 66*Scale, 66*Scale) imageName:@"header_bg"];
    headerImgView.contentMode = UIViewContentModeScaleAspectFill;
    headerImgView.layer.cornerRadius = 33*Scale;
    headerImgView.layer.masksToBounds = YES;
    [topBgView addSubview:headerImgView];
    if (infoModel.avatar && infoModel.avatar.length) {
        [headerImgView sd_setImageWithURL:[NSURL URLWithString:infoModel.avatar]];
    }
    
    UILabel *jobLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, EndY(topBgView)+10*Scale, 200*Scale, 25*Scale) text:[NSString stringWithFormat:@"曾任：%@", infoModel.position] textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    [bottomScrollView addSubview:jobLbl];
    
    UILabel *phoneLbl = [UIToolsControl initLabelWithFrame:CGRectMake(StartX(jobLbl), EndY(jobLbl), ViewWidth(jobLbl), ViewHeight(jobLbl)) text:[NSString stringWithFormat:@"电话：%@", infoModel.telephone] textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    [bottomScrollView addSubview:phoneLbl];
    
    UILabel *emailLbl = [UIToolsControl initLabelWithFrame:CGRectMake(StartX(jobLbl), EndY(phoneLbl), ViewWidth(jobLbl), ViewHeight(jobLbl)) text:[NSString stringWithFormat:@"邮箱：%@", infoModel.email] textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    [bottomScrollView addSubview:emailLbl];
    
    UILabel *specialtyLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, EndY(emailLbl)+15*Scale, 200, 25*Scale) text:@"自我描述" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_18];
    specialtyLbl.font = FontBold(Font_18);
    [bottomScrollView addSubview:specialtyLbl];
    
    NSMutableParagraphStyle *paragraphStyle111 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle111 setLineSpacing:LineSpacingHeight*2];
    NSInteger specialtyHeight = ceil([((infoModel.specialty)?infoModel.specialty:@"待完善") boundingRectWithSize:CGSizeMake(WIDTH-60*Scale, MAXFLOAT) options:(NSStringDrawingUsesFontLeading|NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:Font(Font_13), NSParagraphStyleAttributeName:paragraphStyle111} context:nil].size.height)+1;
//    CGFloat specialtyHeight = [UIToolsControl textHeightWithLineSpacing:((infoModel.specialty)?infoModel.specialty:@"待完善") size:CGSizeMake(WIDTH-60*Scale, MAXFLOAT) font:Font_13]+1;
    UILabel *specialtyContentLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, EndY(specialtyLbl)+10*Scale, WIDTH-60*Scale, specialtyHeight) text:nil textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    specialtyContentLbl.numberOfLines = 0;
    specialtyContentLbl.lineBreakMode = NSLineBreakByWordWrapping;
    [bottomScrollView addSubview:specialtyContentLbl];
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineSpacing = LineSpacingHeight*2;
    specialtyContentLbl.attributedText = [[NSAttributedString alloc] initWithString:((infoModel.specialty)?infoModel.specialty:@"待完善") attributes:@{NSFontAttributeName:Font(Font_13), NSParagraphStyleAttributeName:paraStyle}];
    
    UIView *specialtyLine = [UIToolsControl initViewWithFrame:CGRectMake(30*Scale, EndY(specialtyContentLbl)+20*Scale, WIDTH-60*Scale, lineH) backgroundColor:THEMECOLOR_OF_TEXT_9a9a9a];
    [bottomScrollView addSubview:specialtyLine];
    
    UILabel *currentCNLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, EndY(specialtyLine)+15*Scale, 200, 25*Scale) text:@"求职状态" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_18];
    currentCNLbl.font = FontBold(Font_18);
    [bottomScrollView addSubview:currentCNLbl];
    
    UILabel *currentCNContentLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, EndY(currentCNLbl)+10*Scale, 200, 20*Scale) text:((infoModel.current_cn)?infoModel.current_cn:@"待完善") textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    [bottomScrollView addSubview:currentCNContentLbl];
    
    UIView *currentCNLine = [UIToolsControl initViewWithFrame:CGRectMake(30*Scale, EndY(currentCNContentLbl)+10*Scale, WIDTH-60*Scale, lineH) backgroundColor:THEMECOLOR_OF_TEXT_9a9a9a];
    [bottomScrollView addSubview:currentCNLine];
    
    UILabel *intentionLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, EndY(currentCNLine)+15*Scale, 200, 25*Scale) text:@"求职意向" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_18];
    intentionLbl.font = FontBold(Font_18);
    [bottomScrollView addSubview:intentionLbl];
    
    UILabel *intentionContentLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, EndY(intentionLbl)+10*Scale, WIDTH-60*Scale, 20*Scale) text:[NSString stringWithFormat:@"%@ %@", ((infoModel.intentionModel.jobs_cn)?infoModel.intentionModel.jobs_cn:@"待完善"), ((infoModel.intentionModel.wage_cn)?infoModel.intentionModel.wage_cn:@"")] textColor:THEMECOLOR_OF_TEXT_333333 font:Font_15];
    intentionContentLbl.font = FontBold(Font_15);
    [bottomScrollView addSubview:intentionContentLbl];
    
    UILabel *intentionCityLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, EndY(intentionContentLbl)+10*Scale, WIDTH-60*Scale, 20*Scale) text:[NSString stringWithFormat:@"%@ %@", infoModel.intentionModel.district_cn, infoModel.intentionModel.trade_cn] textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    [bottomScrollView addSubview:intentionCityLbl];
    
    UIView *intentionLine = [UIToolsControl initViewWithFrame:CGRectMake(30*Scale, EndY(intentionCityLbl)+10*Scale, WIDTH-60*Scale, lineH) backgroundColor:THEMECOLOR_OF_TEXT_9a9a9a];
    [bottomScrollView addSubview:intentionLine];
    
    UILabel *workLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, EndY(intentionLine)+15*Scale, 200, 25*Scale) text:@"工作经历" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_18];
    workLbl.font = FontBold(Font_18);
    [bottomScrollView addSubview:workLbl];
    
    CGFloat workEndy = EndY(workLbl);
    for (NSInteger i = 0; i < infoModel.workArray.count; i++) {
        PMineResumeWorkInfoModel *temoModel = infoModel.workArray[i];
        ResumeWorkCell *cell = [[ResumeWorkCell alloc] initWithFrame:CGRectMake(30*Scale, workEndy, WIDTH-60*Scale, temoModel.allHeightOfCompanyLook) type:ResumeWorkCellTypeOfTwoTextDetailImg text:temoModel.company_name detailText:temoModel.job_name time:[NSString stringWithFormat:@"%@-%@", temoModel.start_date, (temoModel.end_date && temoModel.end_date.length)?temoModel.end_date:@"至今"] content:temoModel.desc imgs:temoModel.imgs];
        workEndy += temoModel.allHeightOfCompanyLook;
        [bottomScrollView addSubview:cell];
    }
    
    
    UIView *workLine = [UIToolsControl initViewWithFrame:CGRectMake(30*Scale, workEndy+10*Scale, WIDTH-60*Scale, lineH) backgroundColor:THEMECOLOR_OF_TEXT_9a9a9a];
    [bottomScrollView addSubview:workLine];
    
    UILabel *educationLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, EndY(workLine)+15*Scale, 200, 25*Scale) text:@"教育经历" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_18];
    educationLbl.font = FontBold(Font_18);
    [bottomScrollView addSubview:educationLbl];
    
    CGFloat educationEndy = EndY(educationLbl);
    for (NSInteger i = 0; i < infoModel.educationArray.count; i++) {
        PMineResumeEducationInfoModel *temoModel = infoModel.educationArray[i];
        ResumeWorkCell *cell = [[ResumeWorkCell alloc] initWithFrame:CGRectMake(30*Scale, educationEndy, WIDTH-60*Scale, temoModel.allHeightOfCompanyLook) type:ResumeWorkCellTypeOfTwoTextImg text:temoModel.school detailText:[NSString stringWithFormat:@"%@ %@", temoModel.speciality, temoModel.education_cn] time:[NSString stringWithFormat:@"%@-%@", temoModel.start_date, (temoModel.end_date && temoModel.end_date.length)?temoModel.end_date:@"至今"] content:nil imgs:temoModel.imgs];
        educationEndy += temoModel.allHeightOfCompanyLook;
        [bottomScrollView addSubview:cell];
    }
    
    UIView *trainingLine = [UIToolsControl initViewWithFrame:CGRectMake(30*Scale, educationEndy+10*Scale, WIDTH-60*Scale, lineH) backgroundColor:THEMECOLOR_OF_TEXT_9a9a9a];
    [bottomScrollView addSubview:trainingLine];
    
    UILabel *trainingLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, EndY(trainingLine)+15*Scale, 200, 25*Scale) text:@"培训经历" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_18];
    trainingLbl.font = FontBold(Font_18);
    [bottomScrollView addSubview:trainingLbl];
    
    CGFloat trainingEndy = EndY(trainingLbl);
    for (NSInteger i = 0; i < infoModel.trainingArray.count; i++) {
        PMineResumeTrainingInfoModel *temoModel = infoModel.trainingArray[i];
        ResumeWorkCell *cell = [[ResumeWorkCell alloc] initWithFrame:CGRectMake(30*Scale, trainingEndy, WIDTH-60*Scale, temoModel.allHeightOfCompanyLook) type:ResumeWorkCellTypeOfTwoTextDetailImg text:temoModel.agency detailText:temoModel.course time:[NSString stringWithFormat:@"%@-%@", temoModel.start_date, (temoModel.end_date && temoModel.end_date.length)?temoModel.end_date:@"至今"] content:temoModel.desc imgs:temoModel.imgs];
        trainingEndy += temoModel.allHeightOfCompanyLook;
        [bottomScrollView addSubview:cell];
    }
    
    UIView *projectLine = [UIToolsControl initViewWithFrame:CGRectMake(30*Scale, trainingEndy+10*Scale, WIDTH-60*Scale, lineH) backgroundColor:THEMECOLOR_OF_TEXT_9a9a9a];
    [bottomScrollView addSubview:projectLine];
    
    UILabel *projectLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, EndY(projectLine)+15*Scale, 200, 25*Scale) text:@"项目经验" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_18];
    projectLbl.font = FontBold(Font_18);
    [bottomScrollView addSubview:projectLbl];
    
    CGFloat projectEndy = EndY(projectLbl);
    for (NSInteger i = 0; i < infoModel.projectArray.count; i++) {
        PMineResumeProjectInfoModel *temoModel = infoModel.projectArray[i];
        ResumeWorkCell *cell = [[ResumeWorkCell alloc] initWithFrame:CGRectMake(30*Scale, projectEndy, WIDTH-60*Scale, temoModel.allHeightOfCompanyLook) type:ResumeWorkCellTypeOfOneTextDetailImg text:temoModel.name detailText:nil time:[NSString stringWithFormat:@"%@-%@", temoModel.start_date, (temoModel.end_date && temoModel.end_date.length)?temoModel.end_date:@"至今"] content:temoModel.desc imgs:temoModel.imgs];
        projectEndy += temoModel.allHeightOfCompanyLook;
        [bottomScrollView addSubview:cell];
    }
    
    UIView *credentLine = [UIToolsControl initViewWithFrame:CGRectMake(30*Scale, projectEndy+10*Scale, WIDTH-60*Scale, lineH) backgroundColor:THEMECOLOR_OF_TEXT_9a9a9a];
    [bottomScrollView addSubview:credentLine];
    
    UILabel *credentLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, EndY(credentLine)+15*Scale, 200, 25*Scale) text:@"获得证书" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_18];
    credentLbl.font = FontBold(Font_18);
    [bottomScrollView addSubview:credentLbl];
    
    CGFloat credentEndy = EndY(credentLbl);
    for (NSInteger i = 0; i < infoModel.credentArray.count; i++) {
        PMineResumeCredentInfoModel *temoModel = infoModel.credentArray[i];
        ResumeWorkCell *cell = [[ResumeWorkCell alloc] initWithFrame:CGRectMake(30*Scale, credentEndy, WIDTH-60*Scale, temoModel.allHeightOfCompanyLook) type:ResumeWorkCellTypeOfOneTextImg text:temoModel.name detailText:nil time:temoModel.recieve_date content:nil imgs:@[temoModel.img]];
        credentEndy += temoModel.allHeightOfCompanyLook;
        [bottomScrollView addSubview:cell];
    }
    
    UIView *languageLine = [UIToolsControl initViewWithFrame:CGRectMake(30*Scale, credentEndy+10*Scale, WIDTH-60*Scale, lineH) backgroundColor:THEMECOLOR_OF_TEXT_9a9a9a];
    [bottomScrollView addSubview:languageLine];
    
    UILabel *languageLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, EndY(languageLine)+15*Scale, 200, 25*Scale) text:@"语言能力" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_18];
    languageLbl.font = FontBold(Font_18);
    [bottomScrollView addSubview:languageLbl];
    
    CGFloat languageContenntEndy = EndY(languageLbl);
    for (NSInteger i = 0; i < infoModel.languageArray.count; i++) {
        PMineResumeLanguageInfoModel *temoModel = infoModel.languageArray[i];
        UILabel *languageContenntLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, languageContenntEndy, 200, 25*Scale) text:[NSString stringWithFormat:@"%@ %@", temoModel.language_cn, temoModel.level_cn] textColor:THEMECOLOR_OF_TEXT_666666 font:Font_15];
        languageContenntEndy += 25*Scale;
        [bottomScrollView addSubview:languageContenntLbl];
    }
    
    UIView *tagsLine = [UIToolsControl initViewWithFrame:CGRectMake(30*Scale, languageContenntEndy+10*Scale, WIDTH-60*Scale, lineH) backgroundColor:THEMECOLOR_OF_TEXT_9a9a9a];
    [bottomScrollView addSubview:tagsLine];
    
    UILabel *tagsLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, EndY(tagsLine)+15*Scale, 200, 25*Scale) text:@"特长标签" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_18];
    tagsLbl.font = FontBold(Font_18);
    [bottomScrollView addSubview:tagsLbl];
    
    CGFloat tagsEndy = EndY(tagsLbl);
    if (infoModel && infoModel.tagsArray.count) {
        UIScrollView *tagsScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(30*Scale, tagsEndy+5*Scale, WIDTH-60*Scale, 35*Scale)];
        [bottomScrollView addSubview:tagsScrollView];
        tagsEndy += 40*Scale;
        CGFloat lblWidth = (WIDTH-70*Scale)*0.25;
        CGFloat endX = 0;
        for (NSInteger i = 0; i < infoModel.tagsArray.count; i++) {
            PMineResumeTagsInfoModel *tempModel = infoModel.tagsArray[i];
            CGFloat textWidth = [UIToolsControl textWidth:tempModel.tag_cn size:CGSizeMake(MAXFLOAT, CompanyTagsHeight) font:Font_13]+1;
            CGFloat width = ((lblWidth>textWidth)?lblWidth:textWidth);
            UILabel *lbl = [UIToolsControl initLabelWithFrame:CGRectMake(endX, 5*Scale, width, CompanyTagsHeight) text:tempModel.tag_cn textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
            lbl.textAlignment = NSTextAlignmentCenter;
            lbl.layer.cornerRadius = 2*Scale;
            lbl.layer.masksToBounds = YES;
            lbl.layer.borderColor = THEMECOLOR_OF_TEXT_cccccc.CGColor;
            lbl.layer.borderWidth = 0.5;
            [tagsScrollView addSubview:lbl];
            endX = EndX(lbl)+5*Scale;
        }
        tagsScrollView.contentSize = CGSizeMake(endX, 0);
    }
    
    bottomScrollView.contentSize = CGSizeMake(0, tagsEndy+20*Scale);
}

@end
